package com.bq.gametrade.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.bq.gametrade.R;
import com.bq.gametrade.base.BaseActivity;
import com.bq.gametrade.utils.CheckUtils;

/**
 * 功能：
 * <p>
 *
 * @author Feel on 2016/12/6 14:40
 */

public class ValidationPhoneNumberActivity extends BaseActivity implements View.OnClickListener{

    private ImageView back;
    private TextView tvTitle;
    private EditText edPhoneNumber;
    private Button btnNext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vaildation_phonenumber);
        initView();
    }


    private void initView() {
        back = serchViewById(R.id.image_back);
        back.setOnClickListener(this);
        tvTitle = serchViewById(R.id.title_name);
        tvTitle.setText("绑定账号");
        btnNext = serchViewById(R.id.btn_next);
        btnNext.setOnClickListener(this);
        btnNext.setEnabled(false);
        edPhoneNumber = serchViewById(R.id.et_phoneNumber);
        edPhoneNumber.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                    if(CheckUtils.isMobile(edPhoneNumber.getText().toString())){
                        toastShow("手机号码有效");
                        btnNext.setEnabled(true);
                        btnNext.setTextColor(getResources().getColor(R.color.white));
                        btnNext.setBackground(getResources().getDrawable(R.drawable.bg_btn_blue_selector));
                    }else {
                        btnNext.setTextColor(getResources().getColor(R.color.gray));
                        btnNext.setBackground(getResources().getDrawable(R.drawable.bg_btn_next_normal));
                    }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.image_back:
                finish();
                break;
            case R.id.btn_next:
                Intent intent = new Intent(ValidationPhoneNumberActivity.this,PerfectAccountActivity.class);
                intent.putExtra("phoneNumber",edPhoneNumber.getText().toString());
                startActivity(intent);
                finish();
                break;
        }
    }
}
